package org.hamster.toolkit.main.mediator
{
	import org.hamster.common.components.LoadingMaskComp;
	import org.hamster.common.puremvc.mediator.BaseMediator;
	import org.hamster.common.services.ConfigService;
	import org.hamster.common.services.LoadingMaskService;
	import org.hamster.toolkit.main.events.AppEvent;
	import org.hamster.toolkit.main.utils.PureMVCHelper;
	import org.hamster.toolkit.main.vo.AppConfigVO;
	import org.hamster.toolkit.mainview.IndexViewMediator;
	
	public class AppMediator extends BaseMediator
	{
		public static const NAME:String = "AppMediator";
		
		
		public function AppMediator(viewComponent:Object=null)
		{
			super(NAME, viewComponent);
		}
		
		override public function onRegister():void
		{
			ConfigService.instance.configClazz = AppConfigVO;
			PureMVCHelper.facade = this.facade;
			
			//LoadingMaskService.initInstance(this.app, AppLoadingMask);
			
			facade.registerMediator(new IndexViewMediator(app.indexView));
//			facade.registerCommand(AppEvent.APP_INIT_REQUEST,         AppInitCommand);
//			facade.registerCommand(AppEvent.DROPBOX_INIT_REQUEST,     DropboxInitCommand);
//			facade.registerCommand(AppEvent.DROPBOX_DISPOSE_REQUEST,  DropboxDisposeCommand);
			
//			facade.registerProxy(new AppInitProxy());
//			facade.registerProxy(new AppCheckUpdateProxy());
			
			facade.sendNotification(AppEvent.DROPBOX_INIT_REQUEST);
			
			app.addEventListener(AppEvent.APP_INIT, appInitHandler);
			app.addEventListener(AppEvent.APP_CHECK_UPDATE, appCheckUpdateHandler);
			
		}
		
		private function appInitHandler(event:AppEvent):void
		{
			sendNotification(AppEvent.APP_INIT_REQUEST);
		}
		
		private function appCheckUpdateHandler(event:AppEvent):void
		{
			this.sendNotification(AppEvent.APP_CHECK_UPDATE_REQUEST);
		}
		
		override public function listNotificationInterests():Array
		{
			return [
				AppEvent.APP_INIT_RESPONSE,
			];
		}
		
		public function handleAppInitResponse(data:Object):void
		{
		}
		
		public function get app():HsToolKit
		{
			return viewComponent as HsToolKit;
		}
	}
}